<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=basePath%>/js/jquery-1.9.0.js"></script>
<title>华联宝</title>
<script>
	$(function(){
		var proIds=["1","2"];
		/************根据产品ID获取产品信息************/
		$.each(proIds,function(i,id){
			bindData(id);
		});
		function bindData(id){
			$.ajax({
		         type: "POST",
		         url:"<%=basePath%>invest/getProKinds?proId="+id,
		         dataType:'JSON',
		         success: function(item) {
		        	 showView(item);
		         }
		     });
		}
		/************加载页面信息************/
		function showView(item){
			$("#proId").val(item.pro_id);
			var txt = "<div id=name"+item.pro_id+">"+item.pro_name+"</div>";
			$("#proName").append(txt);
			bindClick($("#name"+item.pro_id),item);
			bindProInfo(item);
		}
		/************绑定点击事件************/
		function bindClick(id,item){
			$(id).click(function(){
				$("#proId").val(item.pro_id)
				bindProInfo(item);
			});
		}
		/************投资按钮点击事件跳转页面************/
		$("#btnInvest").click(function(){
			var proId = $("#proId").val();
			window.location.href="<%=basePath%>invest/investOrder?proId="+proId;
		});
		/************绑定页面产品信息************/
		function bindProInfo(item){
			var minProfit;
			if(parseInt(item.year_profit)>4){
				minProfit = parseInt(item.year_profit)-4;
			}else{
				minProfit = 0;
			}
			var maxProfit = parseInt(item.year_profit)+4;
			$("#planMoney").val("￥"+item.plan_money);
			$("#yearProfit").val(item.year_profit+"%");
			$("#txtExpectedReturn").val(minProfit+"%"+"~"+maxProfit+"%");
			$("#txtCanBuy").val(item.plan_money);
			$("#txtCanBuy").val("￥"+item.can_buy);
			$("#txtLockTime").val(item.pro_cycle+"天");
			$("#txtProStatus").val(item.pro_status);
			/* $("#isShow").append("<span>产品介绍</span>"+item.pro_detail+"<span>还款方式</span>"+item.reply_type+
				"<span>剩余份数</span>"+item.pro_left+"<span>创建人</span>"+item.create_user+"<span>创建时间</span>"+item.create_time
				+"<span>修改时间</span>"+item.update_time+"<span>修改人</span>"+item.update_user); */
		}
		
	});
</script>
</head>
<body>
	<input type="hidden" id="proId">
	<div id="proName"></div>
	<div id="fundInfo">
		<p>计划金额</p><input id='planMoney' disabled='true'/><br/><br/>
		<input id='yearProfit' disabled='true'/><p>年化收益</p>
	</div>
	<div id="productInfo">
		<div id="expectedReturn">
			<span>预期收益率</span>
			<input id='txtExpectedReturn' disabled='true'/>
		</div>
		<div id="canBuy">
			<span>当前可投金额</span><input id='txtCanBuy' disabled='true'/>
		</div>
		<div id="lockTime">
			<span>锁定时间</span><input id='txtLockTime' disabled='true'/>
		</div>
		<div id="proStatus">
			<input id='txtProStatus' disabled='true'/>
		</div>
		<div id="terraceName"></div>
	</div>
	<div id="isShow"></div>
	<div><input id="btnInvest" type="button" value="投资"></div>
</body>
</html>